from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *
from app.window.msg_box import Msg_box

class right_click_menu_device_signal(QObject):
    new_device = Signal()
    save_device = Signal()
    exec_script = Signal()
    script_manager = Signal()
    delete_device = Signal()

class Right_click_menu_devices(QMenu):
    def __init__(self, parent=None):
        super(Right_click_menu_devices, self).__init__(parent)
        self.setTitle("devices")
        self.setContextMenuPolicy(Qt.CustomContextMenu)

        # self.resize(100, 100)
        self.signal = right_click_menu_device_signal()

        self.init_act()
        
        self.msg = Msg_box(self)

    def init_act(self):
        # self.act_new = QAction("添加设备", self)
        self.act_save = QAction("保存设备", self)
        self.act_exec_script = QAction("执行脚本", self)
        self.act_script_manager = QAction("管理脚本", self)
        self.act_del = QAction("删除设备", self)


        # self.act_new.triggered.connect(self.new_device)
        self.act_save.triggered.connect(self.save_device)
        self.act_exec_script.triggered.connect(self.exec_script)
        self.act_script_manager.triggered.connect(self.script_manager)
        self.act_del.triggered.connect(self.del_device)

        # self.addAction(self.act_new)
        self.addAction(self.act_save)
        self.addAction(self.act_exec_script)
        self.addAction(self.act_script_manager)
        self.addAction(self.act_del)

    def new_device(self):
        self.signal.new_device.emit()

    def save_device(self):
        self.signal.save_device.emit()

    def del_device(self):
        if self.msg.msg_is_ok_cancel("确定要删除吗？"):
            self.signal.delete_device.emit()

    def exec_script(self):
        self.signal.exec_script.emit()
    
    def script_manager(self):
        self.signal.script_manager.emit()








class right_click_menu_script_manager_signal(QObject):
    new_script = Signal()
    update_script = Signal()
    search_script = Signal()
    delete_script = Signal()

class Right_click_menu_script_manager(QMenu):
    def __init__(self, parent=None):
        super(Right_click_menu_script_manager, self).__init__(parent)
        self.setTitle("Script_manager")
        self.setContextMenuPolicy(Qt.CustomContextMenu)

        self.signal = right_click_menu_script_manager_signal()

        self.init_act()
        
        self.msg = Msg_box(self)

    def init_act(self):
        self.act_new = QAction("新建", self)
        self.act_update = QAction("修改", self)
        # self.act_search = QAction("搜索", self)
        self.act_del = QAction("删除", self)


        self.act_new.triggered.connect(self.new_script)
        self.act_update.triggered.connect(self.update_script)
        # self.act_search.triggered.connect(self.search_script)
        self.act_del.triggered.connect(self.del_script)

        self.addAction(self.act_new)
        self.addAction(self.act_update)
        # self.addAction(self.act_search)
        self.addAction(self.act_del)

    def new_script(self):
        self.signal.new_script.emit()

    def update_script(self):
        self.signal.update_script.emit()

    def del_script(self):
        if self.msg.msg_is_ok_cancel("确定要删除吗？"):
            self.signal.delete_script.emit()

    def search_script(self):
        self.signal.search_script.emit()